package pl.put.miasi.volleyball;


import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.ContactListener;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.contacts.ContactPoint;

public class RacketContactListener implements ContactListener {

	private World world;
	private Main volleyballMain;
	private Volleyball volleyball;
	
	public RacketContactListener(Volleyball volleyball) {
		this.volleyball = volleyball;
		this.world =  this.volleyball.m_world;
		this.volleyballMain = this.volleyball.parent;
	}
	
	
	@Override
	public void add(ContactPoint cp) {
		Object type1 = cp.shape1.m_body.m_userData;
		Object type2 = cp.shape2.m_body.m_userData;
		if (type1 != null && type2 != null && type2.toString() == "ball")
		{
			if (type1.toString() == "ground")
			{
				volleyball.ballOnGround = true;
				volleyball.ballBody.wakeUp();
				new SoundThread(SoundThread.NEWROUND);			}
			else
			{
				Vec2 currPosition = volleyball.ballBody.getXForm().position;
				//System.out.println("Position: (" + currPosition.x + ", " + currPosition.y + ")");
				new SoundThread(SoundThread.RETURNING);
				
			}
			
			System.out.println(type1.toString() + " hit "+type2.toString());
		}
	}

	@Override
	public void persist(ContactPoint cp) {
		
	}

	@Override
	public void remove(ContactPoint cp) {

	}
	


}
